IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertModuleHit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertModuleHit]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

--------------------------------------------------------------------

--10/15/2009	SP	To insert module names the users have visited.
-----------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertModuleHit]
@modules VARCHAR(MAX), 
@userName VARCHAR(20) 

AS
DECLARE @sqlTransaction VARCHAR(20)
BEGIN TRY

BEGIN TRANSACTION @sqlTransaction

DECLARE @XmlDocumentHandle INT

IF @modules <> ''
BEGIN

EXEC sp_xml_preparedocument @XmlDocumentHandle OUTPUT,@modules

INSERT INTO dbo.Activity_Modules
SELECT @userName,MName
FROM OPENXML(@XmlDocumentHandle,'modules/module')
WITH
(
	MName VARCHAR(50)
)

EXEC sp_xml_removedocument @XmlDocumentHandle
COMMIT TRANSACTION @sqlTransaction
END
END TRY

BEGIN CATCH

ROLLBACK TRANSACTION @sqlTransaction

END CATCH

GO